<script type="text/javascript" src="vue.min.js"></script>
<div id="app">
</div>
<script>
  new Vue({
      el: '#app',
      data: function () {
        return {
        }
      },
      created() {
        this.initWebSocket()
      },
      destroyed: function () {
        this.websocketclose();
      },
      methods: {
        initWebSocket: function () {
          this.websock = new WebSocket("ws://localhost:8080/gzz/websocket");
          this.websock.onopen = this.websocketonopen;
          this.websock.onerror = this.websocketonerror;
          this.websock.onmessage = this.websocketonmessage;
          this.websock.onclose = this.websocketclose;
        },
        websocketonopen: function () {
          console.log("WebSocket连接成功");
        },
        websocketonerror: function (e) {
          console.log("WebSocket连接发生错误");
        },
        websocketonmessage: function (e) {
          console.log(e);
        },
        websocketclose: function (e) {
          console.log("connection closed (" + e.code + ")");
        }
      }
    }

  );
</script>
